package com.xpgk.mvc.ddc.ddc_commomUtil;

import java.text.SimpleDateFormat;
import java.util.Date;

import com.xpgk.annotation.Service;
import com.xpgk.mvc.base.BaseService;
import com.xpgk.mvc.ddc.entity.Picture;

@Service(name = PictureService.serviceName)
public class PictureService  extends BaseService{
	public static final String serviceName = "pictureService";
	
	public Boolean uploadPhoto(String  BASE64,String BUSINESSIDS,String VEHICLEIDS,String PictureType,String pictureName) {
		
		Boolean result = false;
		SimpleDateFormat  sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Picture picture = Picture.dao.findFirst("SELECT * FROM  DDC_PICTURE p WHERE p.BUSINESSIDS = ? AND p.PICTURENAME = ?",BUSINESSIDS,pictureName);
		if (picture == null) {
			picture=new Picture();
			picture.set(Picture.column_VEHICLEIDS, VEHICLEIDS);
			picture.set(Picture.column_TYPE, PictureType);
			picture.set(Picture.column_PICTURENAME, pictureName);
			picture.set(Picture.column_CREATEDATE, sdf.format(new Date()));
			picture.set(Picture.column_BUSINESSIDS, BUSINESSIDS);
			picture.set(Picture.column_PICSTR, BASE64);
			result = picture.save();
		}else{
			picture.set(Picture.column_CREATEDATE, sdf.format(new Date()));
			picture.set(Picture.column_PICSTR, BASE64);
			result = picture.update();
		}
		return result;
	}
}
